package com.seata.demo.controller;

import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.seata.demo.service.AccountService;
import com.seata.demo.util.res.Resp;
import lombok.extern.slf4j.Slf4j;

/**
* @comments
* @author  zg
* @date 2021年2月9日
*/
@Slf4j
@Validated
@RestController
@RequestMapping("/account/rest-service/")
public class AccountRestController {

    @Autowired
    private AccountService accountService;
    
    @PostMapping("deduct-balance")
    Resp<?> deductBalance(String userId, BigDecimal deductMoney){
       Resp<?> resp = null; 
       try {
           resp =  accountService.deductBalance(userId, deductMoney);
        } catch (Exception e) {
            resp = Resp.error(e.getMessage());
            log.error("", e);
        }
       
       return resp;
    }
    
}
